package service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import vo.CartVO;
import dao.CartDAO;

public class CartService {

	private CartDAO cartDAO;
	private ArrayList<CartVO> cart;	
	public CartDAO getCartDAO() {return cartDAO;}
	public void setCartDAO(CartDAO cartDAO) {this.cartDAO = cartDAO;}

	public void insertCart(CartVO cvo) {
		
		for(int i=0; i<cart.size(); i++) {
			String did = cart.get(i).getPid();
			if(did.equals(cvo.getPid())) {
				
			}else {
				cart.add(cvo);
			}
		}
	}
		
		
//		CartVO overlapVO = null;
//		HashMap<String, String> key = new HashMap<String, String>();
//		key.put("cart_id", cvo.getCart_id());
//		key.put("pid", cvo.getPid());
//		System.out.println("key : "+key);
//		try {
//			overlapVO = cartDAO.selectOverlapCart(key);
//			System.out.println("overlapvo : "+overlapVO);
//			if(overlapVO==null) {
//				cartDAO.insertCart(cvo);
//			}else {
//				cartDAO.updateCart(cvo);
//			}
//		}catch(SQLException e){
//			e.printStackTrace();
//		}
//	}
	
	public ArrayList<CartVO> selectAllCart(String cartId) {
		try {
			System.out.println("service cart_id: "+cartId);
			cart = cartDAO.selectAllCart(cartId);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return cart;
	}
}
